/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.application.Platform
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SalesReceiptsUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.salesReceipts.GetEmpOutData;
import com.gys.data.salesReceipts.GetSalesReceiptsTableOutData;
import com.gys.view.salesReceipts.EmpView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class EmpController
extends BaseController
implements Initializable {
    @FXML
    private TableColumn<GetEmpOutData, String> storName;
    @FXML
    private TableColumn<GetEmpOutData, String> no;
    @FXML
    private TableColumn<GetEmpOutData, String> orgName;
    @FXML
    private TableColumn<GetEmpOutData, String> name;
    @FXML
    private TableView<GetEmpOutData> tableView;
    @FXML
    private AnchorPane pane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;
    private ObservableList<GetEmpOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.storName.setCellValueFactory((Callback)new PropertyValueFactory(this.storName.getId()));
        this.no.setCellValueFactory((Callback)new PropertyValueFactory(this.no.getId()));
        this.orgName.setCellValueFactory((Callback)new PropertyValueFactory(this.orgName.getId()));
        this.name.setCellValueFactory((Callback)new PropertyValueFactory(this.name.getId()));
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.tableView)) {
            return;
        }
        this.observableTableList.clear();
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                Platform.runLater((Runnable)new Runnable(){

                    @Override
                    public void run() {
                        EmpView view = SpringUtil.getBean(EmpView.class);
                        Stage stage = (Stage)view.getView().getScene().getWindow();
                        stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                            public void handle(KeyEvent e) {
                                if (e.getCode() == KeyCode.ENTER) {
                                    EmpController.this.sureAction();
                                } else if (e.getCode() == KeyCode.UP) {
                                    int index;
                                    ObservableList outData = EmpController.this.tableView.getSelectionModel().getSelectedItems();
                                    if (outData.size() > 1 && (index = EmpController.this.tableView.getSelectionModel().getSelectedIndex()) >= 1) {
                                        EmpController.this.tableView.getSelectionModel().select(index - 1);
                                    }
                                    EmpController.this.tableView.requestFocus();
                                } else if (e.getCode() == KeyCode.DOWN) {
                                    int index;
                                    ObservableList outData = EmpController.this.tableView.getSelectionModel().getSelectedItems();
                                    if (outData.size() > 1 && (index = EmpController.this.tableView.getSelectionModel().getSelectedIndex()) < outData.size() - 1) {
                                        EmpController.this.tableView.getSelectionModel().select(index + 1);
                                    }
                                    EmpController.this.tableView.requestFocus();
                                }
                                e.consume();
                            }
                        });
                    }
                });
            }
        }, 500L);
        HttpJson httpJson = SalesReceiptsUtil.queryEmp();
        List items = new ArrayList();
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        items = JSON.parseArray((String)httpJson.getMsg(), GetEmpOutData.class);
        this.observableTableList = FXCollections.observableArrayList(items);
        this.tableView.setItems(this.observableTableList);
        this.tableView.getSelectionModel().select(0);
    }

    @FXML
    private void sureAction() {
        GetEmpOutData empOutData = (GetEmpOutData)this.tableView.getSelectionModel().getSelectedItem();
        if (ObjectUtil.isEmpty(empOutData)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u672a\u9009\u62e9\u5bf9\u5e94\u8bb0\u5f55\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01");
            alert.showAndWait();
            return;
        }
        this.salesReceiptsMainController.getEmpF().setText(empOutData.getName());
        GetSalesReceiptsTableOutData selectedItem = (GetSalesReceiptsTableOutData)this.salesReceiptsMainController.getTableView().getSelectionModel().getSelectedItem();
        selectedItem.setEmpName(empOutData.getName());
        selectedItem.setEmpId(empOutData.getEmpId());
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

